home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / hity wydania / Ubuntu 9.10 PL / karmelkowy-koliberek-9.10-netbook-remix-PL.iso / casper / filesystem.squashfs / usr / lib / python2.6 / lib-tk / tkFileDialog.pyc (.txt) < prev    next >
Python Compiled Bytecode  |  2009-11-11  |  5KB  |  154 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. from tkCommonDialog import Dialog
  5.  
  6. class _Dialog(Dialog):
  7.     
  8.     def _fixoptions(self):
  9.         
  10.         try:
  11.             self.options['filetypes'] = tuple(self.options['filetypes'])
  12.         except KeyError:
  13.             pass
  14.  
  15.  
  16.     
  17.     def _fixresult(self, widget, result):
  18.         if result:
  19.             import os as os
  20.             
  21.             try:
  22.                 result = result.string
  23.             except AttributeError:
  24.                 pass
  25.  
  26.             (path, file) = os.path.split(result)
  27.             self.options['initialdir'] = path
  28.             self.options['initialfile'] = file
  29.         
  30.         self.filename = result
  31.         return result
  32.  
  33.  
  34.  
  35. class Open(_Dialog):
  36.     '''Ask for a filename to open'''
  37.     command = 'tk_getOpenFile'
  38.     
  39.     def _fixresult(self, widget, result):
  40.         if isinstance(result, tuple):
  41.             result = []([ getattr(r, 'string', r) for r in result ])
  42.             return result
  43.         if not widget.tk.wantobjects() and 'multiple' in self.options:
  44.             return self._fixresult(widget, widget.tk.splitlist(result))
  45.         return _Dialog._fixresult(self, widget, result)
  46.  
  47.  
  48.  
  49. class SaveAs(_Dialog):
  50.     '''Ask for a filename to save as'''
  51.     command = 'tk_getSaveFile'
  52.  
  53.  
  54. class Directory(Dialog):
  55.     '''Ask for a directory'''
  56.     command = 'tk_chooseDirectory'
  57.     
  58.     def _fixresult(self, widget, result):
  59.         if result:
  60.             
  61.             try:
  62.                 result = result.string
  63.             except AttributeError:
  64.                 pass
  65.  
  66.             self.options['initialdir'] = result
  67.         
  68.         self.directory = result
  69.         return result
  70.  
  71.  
  72.  
  73. def askopenfilename(**options):
  74.     '''Ask for a filename to open'''
  75.     return Open(**options).show()
  76.  
  77.  
  78. def asksaveasfilename(**options):
  79.     '''Ask for a filename to save as'''
  80.     return SaveAs(**options).show()
  81.  
  82.  
  83. def askopenfilenames(**options):
  84.     '''Ask for multiple filenames to open
  85.  
  86.     Returns a list of filenames or empty list if
  87.     cancel button selected
  88.     '''
  89.     options['multiple'] = 1
  90.     return Open(**options).show()
  91.  
  92.  
  93. def askopenfile(mode = 'r', **options):
  94.     '''Ask for a filename to open, and returned the opened file'''
  95.     filename = Open(**options).show()
  96.     if filename:
  97.         return open(filename, mode)
  98.  
  99.  
  100. def askopenfiles(mode = 'r', **options):
  101.     '''Ask for multiple filenames and return the open file
  102.     objects
  103.  
  104.     returns a list of open file objects or an empty list if
  105.     cancel selected
  106.     '''
  107.     files = askopenfilenames(**options)
  108.     if files:
  109.         ofiles = []
  110.         for filename in files:
  111.             ofiles.append(open(filename, mode))
  112.         
  113.         files = ofiles
  114.     
  115.     return files
  116.  
  117.  
  118. def asksaveasfile(mode = 'w', **options):
  119.     '''Ask for a filename to save as, and returned the opened file'''
  120.     filename = SaveAs(**options).show()
  121.     if filename:
  122.         return open(filename, mode)
  123.  
  124.  
  125. def askdirectory(**options):
  126.     '''Ask for a directory, and return the file name'''
  127.     return Directory(**options).show()
  128.  
  129. if __name__ == '__main__':
  130.     enc = 'utf-8'
  131.     import sys
  132.     
  133.     try:
  134.         import locale
  135.         locale.setlocale(locale.LC_ALL, '')
  136.         enc = locale.nl_langinfo(locale.CODESET)
  137.     except (ImportError, AttributeError):
  138.         pass
  139.  
  140.     openfilename = askopenfilename(filetypes = [
  141.         ('all files', '*')])
  142.     
  143.     try:
  144.         fp = open(openfilename, 'r')
  145.         fp.close()
  146.     except:
  147.         print 'Could not open File: '
  148.         print sys.exc_info()[1]
  149.  
  150.     print 'open', openfilename.encode(enc)
  151.     saveasfilename = asksaveasfilename()
  152.     print 'saveas', saveasfilename.encode(enc)
  153.  
  154.